export type User = {
  id: string;
  name: string;
  photo: string;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
}

export type Profile = {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;
  intro: string | null;
}

const initState = {
  user: {} as User,
  profile: {} as Profile
}

type UserAction =
  { type: 'user/saveUser', payload: User }
  | { type: 'user/saveProfile', payload: Profile }


export function userReducer(preState = initState, action: UserAction) {
  switch (action.type) {
    case 'user/saveUser':
      return { ...preState, user: action.payload }

    case 'user/saveProfile':
      return { ...preState, profile: action.payload }

    default:
      return preState;
  }
}